<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>ifmsg基础测试</title>
		<script src="../../utils.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../dist/xsloader.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body>
		<p>
			这是父页面：
			<div id="logDiv">

			</div>
			<iframe id="iframe" src="sub.html" style="width:100%;height:300px"></iframe>
			<iframe id="iframe2" src="sub2.html" style="width:100%;height:300px"></iframe>
		</p>
		<script type="text/javascript">
			xsloader({});
			require(["ifmsg"], function(ifmsg) {
				ifmsg.debug.logMessage=true;
				
				var server=new ifmsg.Server();
				server.onConnect=(client,conndata,callback)=>{
					divLog("onConnect");
					callback(true);
				};
				server.onConnected=(client)=>{
					divLog("onConnected");
					client.onMessage=function(data){
						divLog(data);
					}
					
					client.sendMessage("来自父页面");
					
					client.onRequest=function(data,resolve,reject){
						divLog("onRequest:",data);
						
						if(data.indexOf("页面1")>=0){
							reject("reject回复request");
						}else{
							resolve("resolve回复request");
						}
					}
				}
				server.listen();
			});
		</script>
	</body>

</html>